package com.campus.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.campus.dao.ManagerTeacherMapper;
import com.campus.entry.ManagerTeacher;
import com.campus.pojo.dto.TeacherDto;
import com.campus.service.ManagerTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

@Service
public class ManagerTeacherServiceImpl implements ManagerTeacherService {
    @Autowired
    private ManagerTeacherMapper managerTeacherMapper;

    /**
     * 插入教师
     * @param managerTeacher
     */
    @Override
    public void saveTeacher(ManagerTeacher managerTeacher) {
        managerTeacherMapper.insert(managerTeacher);
    }

    /**
     * 根据Id查询教师
     * @param managerTeacherId
     * @return {@link ManagerTeacher }
     */
    @Override
    public ManagerTeacher getTeacherById(Integer managerTeacherId) {
        LambdaQueryWrapper<ManagerTeacher> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(ManagerTeacher::getId,managerTeacherId);
        return managerTeacherMapper.selectOne(lambdaQueryWrapper);
    }

    /**
     * 根据教师信息筛选教师
     * @param teacherDto
     * @return {@link List }<{@link ManagerTeacher }>
     */
    @Override
    public List<ManagerTeacher> getTeacherBy(TeacherDto teacherDto) {
       LambdaQueryWrapper<ManagerTeacher> lambdaQueryWrapper=new LambdaQueryWrapper<>();
       if (isNull(teacherDto.getTeacherName())){
           lambdaQueryWrapper.eq(ManagerTeacher::getTeacherName,teacherDto.getTeacherName());
       }
       if (isNull(teacherDto.getProfession())){
           lambdaQueryWrapper.eq(ManagerTeacher::getProfession,teacherDto.getProfession());
       }
       if (isNull(teacherDto.getSchool())){
           lambdaQueryWrapper.eq(ManagerTeacher::getSchool,teacherDto.getSchool());
       }
       if (isNull(teacherDto.getSubject())){
           lambdaQueryWrapper.eq(ManagerTeacher::getSubject,teacherDto.getSubject());
       }
       return   managerTeacherMapper.selectList(lambdaQueryWrapper);

    }
    private boolean isNull(String s){
        return !Objects.isNull(s) && !s.isEmpty();
    }
}
